
ny <- dget(here::here("DataCollection/PNAS analysis/Data", "nyONALing.rda"))
ch <- dget(here::here("DataCollection/PNAS analysis/Data", "chLing.rda"))



# Make IPL-12 variables
ny$ling12s <- rescale(ny$read + ny$speak, to = c(0, 1), from = c(2, 10))
ny$ling24s <- rescale(ny$read + ny$speak + ny$listen + ny$write, to = c(0, 1), from = c(4, 20))

ch$ling12s <- rescale(ch$read + ch$speak, to = c(0, 1), from = c(2, 10))
ch$ling24s <- rescale(ch$read + ch$speak + ch$listen + ch$write, to = c(0, 1), from = c(4, 20))

# Make plots
chLing12 <- ggplot(ch, aes(x = ling12s)) +
  geom_density(color = '#8da0cb') + 
  theme_minimal() +
  coord_cartesian(ylim = c(0, 2.25)) +
  ylab("") +
  xlab("IPL-12 ling. int., survey 7 (see table S2)") +
  theme(axis.text.y = element_text(size = 6),
        axis.text.x = element_text(size = 6),
        text = element_text(size = 8)
  ) +
  annotate("text", x = 0.8, y = 2.2, label = "N = 128", size = 2) 

chLing24 <- ggplot(ch, aes(x = ling24s)) +
  geom_density(color = '#8da0cb') + 
  theme_minimal() +
  coord_cartesian(ylim = c(0, 2.25)) +
  ylab("") +
  xlab("IPL-24 ling. int., survey 7 (see table S2)") +
  theme(axis.text.y = element_text(size = 6),
        axis.text.x = element_text(size = 6),
        text = element_text(size = 8)
  ) +
  annotate("text", x = 0.8, y = 2.2, label = "N = 128", size = 2) 

nyLing12 <- ggplot(ny, aes(x = ling12s)) +
  geom_density(color = '#8da0cb') + 
  theme_minimal() +
  coord_cartesian(ylim = c(0, 2.25)) +
  ylab("") +
  xlab("IPL-12 ling. int., survey 6 (see table S2)") +
  theme(axis.text.y = element_text(size = 6),
        axis.text.x = element_text(size = 6),
        text = element_text(size = 8)
  ) +
  annotate("text", x = 0.8, y = 2.2, label = "N = 257", size = 2) 

nyLing24 <- ggplot(ny, aes(x = ling24s)) +
  geom_density(color = '#8da0cb') + 
  theme_minimal() +
  coord_cartesian(ylim = c(0, 2.25)) +
  ylab("") +
  xlab("IPL-24 ling. int., survey 6 (see table S2)") +
  theme(axis.text.y = element_text(size = 6),
        axis.text.x = element_text(size = 6),
        text = element_text(size = 8)
  ) +
  annotate("text", x = 0.8, y = 2.2, label = "N = 253", size = 2) 



# Export plots
lingDisp <- arrangeGrob(chLing12, nyLing12, chLing24, nyLing24, nrow = 2, left = "Density")
ggsave(here::here("Draft/PNAS/draft/plots", "lingDisp.pdf"), lingDisp, height = (17.8 / 2.414), width = 17.8, units = "cm")
